package cn.iocoder.yudao.module.member.controller.admin.faceanalyserequest;

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.dal.dataobject.faceanalyseresult.FaceanalyseResultDO;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.security.PermitAll;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.faceanalyserequest.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.faceanalyserequest.FaceanalyseRequestDO;
import cn.iocoder.yudao.module.member.service.faceanalyserequest.FaceanalyseRequestService;

@Tag(name = "管理后台 - 会员皮肤状态分析请求")
@RestController
@RequestMapping("/member/faceanalyse-request")
@Validated
public class FaceanalyseRequestController {

    @Resource
    private FaceanalyseRequestService faceanalyseRequestService;

    @PostMapping("/create")
    @Operation(summary = "创建会员皮肤状态分析请求")
//    @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:create')")
    public CommonResult<FaceanalyseResultDO> createFaceanalyseRequest(@Valid @RequestBody FaceanalyseRequestSaveReqVO createReqVO) throws JsonProcessingException {
        return success(faceanalyseRequestService.createFaceanalyseRequest(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员皮肤状态分析请求")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:update')")
    public CommonResult<Boolean> updateFaceanalyseRequest(@Valid @RequestBody FaceanalyseRequestSaveReqVO updateReqVO) {
        faceanalyseRequestService.updateFaceanalyseRequest(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除会员皮肤状态分析请求")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:delete')")
    public CommonResult<Boolean> deleteFaceanalyseRequest(@RequestParam("id") Long id) {
        faceanalyseRequestService.deleteFaceanalyseRequest(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除会员皮肤状态分析请求")
                @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:delete')")
    public CommonResult<Boolean> deleteFaceanalyseRequestList(@RequestParam("ids") List<Long> ids) {
        faceanalyseRequestService.deleteFaceanalyseRequestListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得会员皮肤状态分析请求")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:query')")
    public CommonResult<FaceanalyseRequestRespVO> getFaceanalyseRequest(@RequestParam("id") Long id) {
        FaceanalyseRequestDO faceanalyseRequest = faceanalyseRequestService.getFaceanalyseRequest(id);
        return success(BeanUtils.toBean(faceanalyseRequest, FaceanalyseRequestRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得会员皮肤状态分析请求分页")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:query')")
    public CommonResult<PageResult<FaceanalyseRequestRespVO>> getFaceanalyseRequestPage(@Valid FaceanalyseRequestPageReqVO pageReqVO) {
        PageResult<FaceanalyseRequestDO> pageResult = faceanalyseRequestService.getFaceanalyseRequestPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FaceanalyseRequestRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出会员皮肤状态分析请求 Excel")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-request:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFaceanalyseRequestExcel(@Valid FaceanalyseRequestPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<FaceanalyseRequestDO> list = faceanalyseRequestService.getFaceanalyseRequestPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "会员皮肤状态分析请求.xls", "数据", FaceanalyseRequestRespVO.class,
                        BeanUtils.toBean(list, FaceanalyseRequestRespVO.class));
    }

}